package com.etmvc.controller.auth;

import org.apache.commons.lang.StringUtils;

import com.etmvc.core.FrontController;

public class LoginController extends FrontController{
	public void index(){
	}
	
	public void login(String name,String pword){
		String redirect = request.getParameter("r");
		if (redirect == null || "".equals(redirect)) {
			redirect = "/auth/space";
		}
		//查数据库，校验用户合法性。。。
		if (!StringUtils.isEmpty(name)) {
			session.setAttribute("MANAGER", name);
		}else {
			redirect = "/auth/login?r="+redirect;
		}
		try {
			redirect(redirect);
		} catch (Exception e) {
			System.out.println("login redirect error!");
		}
	}
	
	public void logout(){
		if (session!=null) {
			session.setAttribute("MANAGER", null);
		}
		try {
			redirect("/auth/space");
		} catch (Exception e) {
			System.out.println("logout redirect error!");
		}
	}
}
